package com.wms.controller;


import com.wms.domain.Result;
import com.wms.vo.UserVo;
import com.wms.domain.User;
import com.wms.dto.UserDto;
import com.wms.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/user")
@RestController
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping
    public UserVo list(UserDto queryParam) {
        return userService.list(queryParam);
    }

    @PostMapping
    public Result insert(@RequestBody User user) {
        return Result.success(userService.insert(user));
    }

    @GetMapping("/{id}")
    public Result showBack(@PathVariable Integer id) {
        return Result.success(userService.getInfo(id));
    }

    @PutMapping
    public Result update(@RequestBody User user) {
        System.out.println("user = " + user);
        return Result.success(userService.update(user));
    }

    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Integer> ids) {
        return Result.success(userService.deleteByIds(ids));
    }
}
